﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EasyUI.Master" AutoEventWireup="true" CodeBehind="Listm.aspx.cs" Inherits="cebao.Web.info.Listm" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../ckeditor/ckeditor.js"></script>
    <script src="../Script/cloud-zoom.1.0.2.min.js"></script>
    <script src="../ckeditor/adapters/jquery.js"></script>
    <script src="../Script/sitedata.js"></script>
    <script src="../Script/combobox.js"></script>
    <script src="../Script/city.js"></script>
    <script type="text/javascript">
        var provinceName;
        var cityName;
        var arrCity;
        var areaName;
        var arrArea;
        var rowid;
        Date.prototype.pattern = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份        
                "d+": this.getDate(), //日        
                "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时        
                "H+": this.getHours(), //小时        
                "m+": this.getMinutes(), //分        
                "s+": this.getSeconds(), //秒        
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度        
                "S": this.getMilliseconds() //毫秒        
            };
            var week = {
                "0": "/u65e5",
                "1": "/u4e00",
                "2": "/u4e8c",
                "3": "/u4e09",
                "4": "/u56db",
                "5": "/u4e94",
                "6": "/u516d"
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            if (/(E+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        }
        var Common = {

            //EasyUI用DataGrid用日期格式化
            TimeFormatter: function (value, rec, index) {
                if (value == undefined) {
                    return "";
                }
                /*json格式时间转js时间格式*/
                value = value.substr(1, value.length - 2);
                var obj = eval('(' + "{Date: new " + value + "}" + ')');
                var dateValue = obj["Date"];
                if (dateValue.getFullYear() < 1900) {
                    return "";
                }
                var val = dateValue.pattern("yyyy-MM-dd HH:mm");
                return val;
            },
            DateTimeFormatter: function (value, rec, index) {

                if (value == null || value == '') {
                    return '';
                }
                var dt;
                if (value instanceof Date) {
                    dt = value;
                }
                else {
                    dt = new Date(value);
                    if (isNaN(dt)) {
                        value = value.replace(/\/Date\((-?\d+)\)\//, '$1'); //标红的这段是关键代码，将那个长字符串的日期值转换成正常的JS日期格式
                        dt = new Date();
                        dt.setTime(value);
                    }
                }
                return dt.pattern("yyyy年M月d日");
            },

            //EasyUI用DataGrid用日期格式化
            DateFormatter: function (value, rec, index) {
                if (value == undefined) {
                    return "";
                }
                /*json格式时间转js时间格式*/
                value = value.substr(1, value.length - 2);
                var obj = eval('(' + "{Date: new " + value + "}" + ')');
                var dateValue = obj["Date"];
                if (dateValue.getFullYear() < 1900) {
                    return "";
                }

                return dateValue.pattern("yyyy-MM-dd");
            }
        };
        function CKupdate() {
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[instance].updateElement();
            CKEDITOR.editorConfig = function (config) {
                config.height = 100; //高度
                config.toolbar = 'Basic';
            };

            //CKEDITOR.replace('infocontent', {
            //    toolbar:
            //        [
            //            ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink', '-', 'linkbutton']
            //        ]
            //});
        }
        $(function () {
            InitGird();
            InitSearch();
            showpic();
        });
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '发布信息列表', //表格标题
                url: 'GetMinfo.ashx', //请求数据的页面
                sortName: 'searchTime', //排序字段
                idField: 'mobileSendSearchInfoId', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() -35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                method: 'post',
                singleSelect: true,
                columns: [[
	                { title: '标题', field: 'searchInfo', width: 150 },
                    {
                        title: '发布时间', field: 'searchTime', width: 150, sortable: true, formatter: function (value, row, index) {
                            if (value != "") {
                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/");
                                return new Date(value).pattern("yyyy年M月d日");
                            }
                        }
                    },
                    { title: '发送人', field: 'utruename', width: 150 },
                    {
                        title: '地区', field: 'uprovince', width: 150, formatter: function (value, row, index) {
                            return row.uprovince + row.ucity + row.ucounty

                        }
                    },
                    { title: '单位', field: 'uunit', width: 150 },
                    { title: '电话', field: 'uphone', width: 150 },
                    { title: '回复', field: 'nums', width: 150 },
                    {
                        title: '查看', field: 'iid', width: 80, formatter: function (value, row, index) {

                            return '<a style="color:red" href="javascript:" onclick="$(this).parent().click();newUser(' + value + ');return false;">详细信息</a>';
                        }
                    },
                    {
                        title: '操作', field: 'pid', width: 80, formatter: function (value, row, index) {
                            return '&nbsp;<a style="color:red" href="javascript:" onclick="$(this).parent().click();removeUser();return false;">删除</a>';

                        }
                    }


                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });


        }
        //初始化搜索框
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                searcher: function (val, name) {
                    $('#tt').datagrid('options').queryParams.search_type = name;
                    $('#tt').datagrid('options').queryParams.search_value = val;
                    $('#tt').datagrid('options').queryParams.uprovince = $("#uprovince").combobox("getValue");
                    $('#tt').datagrid('options').queryParams.ucity = $("#ucity").combobox("getValue");
                    $('#tt').datagrid('options').queryParams.ucounty = $("#ucounty").combobox("getValue");
                    $('#tt').datagrid('reload');
                },
                prompt: '请输入查询信息'
            });
            loadNameEdit();
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    $('#level').val(data[0].level);
                    if (data[0].level == 3) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        $("#dprovince").hide();
                    }
                    if (data[0].level == 2) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        cityName = data[0].city;
                        $('#ucity').combobox('setValue', data[0].city);
                        $("#dprovince").hide();
                        $("#dcity").hide();
                    }
                    if (data[0].level == 1) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        cityName = data[0].city;
                        $('#ucity').combobox('setValue', data[0].city);
                        areaName = data[0].county;
                        $('#ucounty').combobox('setValue', data[0].county);
                        $("#dprovince").hide();
                        $("#dcity").hide();
                        $("#dcounty").hide();
                    }
                }
            });
            $('#infocontent').ckeditor();
            CKupdate();
        }

        function newUser() {
            //清空内容  
            $('#fm').form('clear');
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要查看的行！", "info");
            }
            if (row) {
                rowid = row.mobileSendSearchInfoId;
                $('#iid').val(rowid);
                $('#searchInfo').text(row.searchInfo);
                $('#uid').val(row.uid);
                updateinfo();
                //$("#showpic").click();
                if (row.ispic == 1) {
                    $('#mpic').attr("src", "GetMinfo.ashx?action=pic&mid=" + rowid);
                    //$('#mpica').attr("href", "GetMinfo.ashx?action=pic&mid=" + rowid);
                    //$('#mpic').attr("width", 100);
                    //$('#mpic').attr("height", 100);
                    //$('#mypic').show();
                }
                else {
                    //$('#mypic').hide();
                }
                document.getElementById("test").value = "add";
                $('#dlg').dialog('open').dialog('setTitle', '查看回复信息');
                CKupdate();
            }
        }
        function updateinfo() {
            var result = $.ajax({
                url: "GetMinfo.ashx?action=getinfo&iid=" + rowid,
                type: 'post',
                dataType: 'json',
                async: false,
                cache: false
            }).responseText;
            $('#oinfo').html(result);
        }
        function saveUser() {
            CKupdate();
            var f = $('#fm');
            f.form('submit', {
                url: "GetMinfo.ashx?action=add",
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    if (result.indexOf("T") == 0) {
                        //$('#dlg').dialog('close');
                        $.messager.alert("提示", "恭喜您，回复信息成功", "info");
                        updateinfo();
                    }
                    else if ((result.indexOf("F") == 0)) {
                        $.messager.alert("提示", "回复信息失败，请重新操作！", "info");
                        return;
                    }
                    else if ((result.indexOf("L") == 0)) {
                        $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                        top.location = '/index.aspx';
                        return;
                    }
                }
            });
        }
        function showpic() {
            //var x = 10;
            //var y = 20;
            //$("#mpic").mouseover(function (e) {
            //    var tooltip = "<div id='tooltip' ><img src='" + this.src + "' /> </div>  "; //创建 div 元素
            //    if ($.trim($("#showpic").html().trim()) == "") {
            //        $("#showpic").append(tooltip); //把它追加到文档中
            //        $("#tooltip").show("slow");
            //        $("#showpic").click(function () {
            //            $("#tooltip").remove();
            //            $("#mpic").show();
            //            //移除
            //        });
            //        $("#mpic").hide();
            //    }
            //}).click(function () {
            //    $("#tooltip").remove();
            //    $("#mpic").show();//移除
            //});
            //.mousemove(function (e) {
            //    $("#tooltip").css({
            //        "top": (e.pageY + y) + "px",
            //        "left": (e.pageX + x) + "px"
            //    });
            //});
        }

        function removeUser() {
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetMinfo.ashx?pid=' + row.mobileSendSearchInfoId + "&action=delete",
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    $('#tt').datagrid('reload');
                                }
                                else {
                                    $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }

    </script>
    <style type="text/css">
        .fitem {
            float: left;
            margin-right: 5px;
        }

        .fitemy {
            margin-right: 5px;
        }

        .fitem label {
            width: 40px;
            line-height: 24px;
        }

        .info {
            margin: 5px;
            padding: 5px;
            border: 1px solid green;
        }

        .suser {
            font-size: 18px;
        }

            .suser .ftime {
                float: right;
            }

        #tooltip {
            /*position:absolute;*/
        }

        .biaoti {
            height: 30px;
            background: #f4f4f4;
            line-height: 30px;
            padding-left: 15px;
            color: #0e2d5f;
            font-weight: bold;
        }

        .huifu {
            height: 30px;
            float: left;
            line-height: 30px;
            padding-left: 15px;
        }

        .huifubianjikuang {
            height: 300px;
        }

        .liuyan {
            height: auto;
            margin-top: 15px;
            border: 1px #e4e1e1 solid;
        }

        .liuyantop {
            height: 30px;
            line-height: 30px;
            background: #e4eeff;
            padding-left: 15px;
        }

        .liuyancontent {
            height: auto;
            padding: 5px;
            background: #f4f4f4;
            margin-top: 1px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>
                <td style="padding-left: 2px">
                    <div class="fitem" id="dprovince">
                        <label>省：</label>
                        <input id="uprovince" name="uprovince" class="easyui-combobox" data-options="width:'100'" />
                    </div>
                    <div class="fitem" id="dcity">
                        <label>市：</label>
                        <input id="ucity" name="ucity" class="easyui-combobox" data-options="width:'150'" />
                    </div>
                    <div class="fitem" id="dcounty">
                        <label>县：</label>
                        <input id="ucounty" name="ucounty" class="easyui-combobox" data-options="width:'150'" />
                    </div>
                    <input id="ipt_search" menu="#search_menu" />
                    <div id="search_menu" style="width: 120px">
                        <div name="usernum">
                            标题
                        </div>
                        <div name="username">
                            发布人
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="dlg" class="easyui-dialog" style="width: 850px; height: 500px; padding: 5px; overflow: auto;"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">
        <form id="fm" method="post">
            <div class="fitemy biaoti">
                <label>信息：</label>
                <span id="searchInfo" name="searchInfo"></span>
            </div>
            <div class="fitemy" style="float: left; width: 395px;" id="mypic">
                <img id="mpic" src="" width="395" height="400" />
            </div>
            <div class="fitemy" style="float: right; width: 400px;">
                <textarea class="ckeditor" id="infocontent" name="infocontent" rows="5"></textarea>
                <input name="iid" id="iid" type="hidden" />
                <input name="uid" id="uid" type="hidden" />
                <input name="Test" id="test" type="hidden" />
                <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />
            </div>
            <div style="clear: both;"></div>

            <div class="fitemy biaoti">
                <label>其它人回复：</label>

            </div>
            <div id="oinfo" style="margin-bottom: 10px;"></div>

        </form>
    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">回复</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close');$('#tt').datagrid('reload');">关闭</a>
    </div>

</asp:Content>


